package leetcode.code1615;

public class Solution {
	public int maximalNetworkRank(int n, int[][] roads) {
		int[] cnt = new int[n];
		int[][] z = new int[n][n];
		for (int[] road : roads) {
			int a = road[0], b = road[1];
			cnt[a]++;
			cnt[b]++;
			z[a][b] = 1;
			z[b][a] = 1;
		}
		int ans = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				ans = Math.max(ans, cnt[i] + cnt[j] - z[i][j]);
			}
		}
		return ans;
	}
}
